<!--
 * @Description: 
 * @Author: admin
 * @Date: 2021-06-10 10:45:51
 * @LastEditors: admin
 * @LastEditTime: 2021-06-10 11:05:18
-->
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>React</title>
  <!-- 引入react依赖 -->
  <script src="./react.development.js"></script>
  <script src="./react-dom.development.js"></script>
  <!-- jsx语法解析 -->
  <script src="./babel.min.js"></script>
</head>

<body>
  <div id="root">

  </div>
</body>
<script type="text/babel">
  // function Clock(props) {
  //   return (
  //     <div>
  //     <h1>Hello，World</h1>
  //     <h2>当前时间是{props.date.toLocaleTimeString()}</h2>
  //   </div>
  //   )
  // }
  class Clock extends React.Component{
    constructor(props){
      super(props);
      this.state = {date:new Date()};
    }
    componentDidMount(){
      // 在组件被渲染到dom时执行
      this.timer = setInterval(
        ()=>this.myTime(),
        1000
      )
    }
    componentWillUnmount(){
      clearInterval(this.timer);
    }
    myTime(){
      this.setState({
        date: new Date()
      })
    }
    render(){
      return (
      <div>
        <h1>Hello，World</h1>
        <h2>当前时间是{this.state.date.toLocaleTimeString()}</h2>
      </div>
      )
    }
  }
  function App(){
    return (
      <div>
        <Clock />,
        <Clock />,
        <Clock />,
      </div>
    )
  }
  ReactDOM.render(
    <App />,
    document.getElementById('root')
  );
  

</script>

</html>